const express = require("express");
const jwt = require("jsonwebtoken");
const expressJwt = require("express-jwt");
const testService = require("../services/testTable");
const { secretKey } = require("../constant/constant");

let router = express.Router();

router.post("/getTableList", async (req, res, next) => {
    try {
        const { user_type } = req.body;
        const result = await testService.getTable();

        let data = [];
        result.forEach(item => {
            data.push(item);
        });
        console.log(data);
        res.send({ code: 200, msg: "请求成功", data: data });
    } catch (e) {
        next(e);
    }
});

router.post("/getTableData", async (req, res, next) => {
    try {
        const { user_type } = req.body;
        const result = await testService.getTableData();

        let data = [];
        result.forEach(item => {
            data.push(item);
        });
        console.log(data);
        res.send({ code: 200, msg: "请求成功", data: data });
    } catch (e) {
        next(e);
    }
});

router.post("/getDialogData", async (req, res, next) => {
    try {
        const { user_type } = req.body;
        const result = await testService.getDialogData();

        let data = [];
        result.forEach(item => {
            data.push(item);
        });
        console.log(data);
        res.send({ code: 200, msg: "请求成功", data: data });
    } catch (e) {
        next(e);
    }
});

router.post("/getDeviceData", async (req, res, next) => {
    try {
        const { user_type } = req.body;
        const result = await testService.getDeviceData();

        let data = [];
        result.forEach(item => {
            data.push(item);
        });
        console.log(data);
        res.send({ code: 200, msg: "请求成功", data: data });
    } catch (e) {
        next(e);
    }
});

router.post("/getLevelData", async (req, res, next) => {
    try {
        const { user_type } = req.body;
        const result = await testService.getLevelData();

        let data = [];
        result.forEach(item => {
            data.push(item);
        });
        console.log(data);
        res.send({ code: 200, msg: "请求成功", data: data });
    } catch (e) {
        next(e);
    }
});

router.post("/getDeviceTypeData", async (req, res, next) => {
    try {
        const { user_type } = req.body;
        const result = await testService.getDeviceTypeData();

        let data = [];
        result.forEach(item => {
            data.push(item);
        });
        console.log(data);
        res.send({ code: 200, msg: "请求成功", data: data });
    } catch (e) {
        next(e);
    }
});

router.post("/getFactoryData", async (req, res, next) => {
    try {
        const { user_type } = req.body;
        const result = await testService.getFactoryData()

        let data = [];
        result.forEach(item => {
            data.push(item);
        });
        console.log(data);
        res.send({ code: 200, msg: "请求成功", data: data });
    } catch (e) {
        next(e);
    }
});

module.exports = router;
